/*
 * ResourceGeneratorFilter.h
 *
 *  Created on: Nov 20, 2008
 *      Author: Ryan
 */

#ifndef RESOURCEGENERATORFILTER_H_
#define RESOURCEGENERATORFILTER_H_

#include "../../../OOInterface/Interfaces/UnitVisitor.h"

class ResourceGeneratorFilter: public FilterVisitor
{
public:
	ResourceGeneratorFilter( const OOInterface::ResourceList& list ):
		_isResourceGenerator(false), _resources( list )
	{}
	virtual ~ResourceGeneratorFilter() {}

	virtual void visitUnit( const OOInterface::Unit& u )
	{
		for( OOInterface::ResourceList::const_iterator resource = _resources.begin(); resource != _resources.end(); ++resource )
		{
			if( u.getResourceGeneration( *resource ) - u.getResourceUpkeep( *resource ) > 0.0f )
				_isResourceGenerator = true;
		}

	}

	virtual void visitAirAspect( const OOInterface::AirAspect& a ){}
	virtual void visitLandAspect( const OOInterface::LandAspect& a ){}
	virtual void visitWaterAspect( const OOInterface::WaterAspect& a ){}

	virtual void visitBuilderAspect( const OOInterface::BuilderAspect& a ) {}
	virtual void visitBuildingAspect( const OOInterface::BuildingAspect& a ) {}
	virtual void visitTransportAspect( const OOInterface::TransportAspect& a ){}

	virtual void visitReclaimableAspect( const OOInterface::ReclaimableAspect& a ){}
	virtual void visitResourceExtractorAspect( const OOInterface::ResourceExtractorAspect& a ) {}

	virtual bool isFiltered() { return !isGenerator(); }
	bool isGenerator() { return _isResourceGenerator; }
	virtual void reset() { _isResourceGenerator = false; }

private:
	bool _isResourceGenerator;
	const OOInterface::ResourceList& _resources;
};

#endif /* RESOURCEGENERATORFILTER_H_ */
